import {http} from "@/service/http";
import {IntPageQuery, Page} from "@/types/response";
import {Department, DepartmentTree} from "@/types/user";

const prefix = '/Department'


/**
 * 删除department
 * @param id
 * @returns
 */
export const removeDepartment = (id: string | number) => {
  return http({
    method: 'DELETE',
    url: `${prefix}/Delete/${id}`,
  })
}


/**
 * 删除department
 * @param page
 * @returns
 */
export const getDepartmentByPage = (page: IntPageQuery) => {
  if (!page?.intPageSize) {
    page.intPageSize = 50
  }
  return http<Page<Department[]>>({
    method: 'GET',
    url: `${prefix}/Get`,
    params: {
      ...page
    }
  })
}

/**
 * 获取 department
 * @param id
 * @returns
 */
export const getDepartmentById = (id: string | number) => {
  return http<Department>({
    method: 'GET',
    url: `${prefix}/Get/${id}`,
  })
}


/**
 * 获取 department tree
 * @param pid
 * @returns
 */
export const getDepartmentTree = (pid: string | number) => {
  return http<DepartmentTree>({
    method: 'GET',
    url: `${prefix}/GetDepartmentTree`,
  })
}


/**
 * 查询 department tree
 * @param f
 * @param key
 * @returns
 */
export const getTreeTable = (f: string | number, key: string = '') => {
  return http<Page<Department[]>>({
    method: 'GET',
    url: `${prefix}/GetTreeTable`,
    params: {
      f, key
    }
  })
}


/**
 * create department
 * @param department
 * @returns
 */
export const createDepartment = (department:Department) => {
  return http({
    method: 'POST',
    url: `${prefix}/Post`,
    data: {
      ...department
    }
  })
}


/**
 * update department
 * @param department
 * @returns
 */
export const updateDepartment = (department:Department) => {
  return http({
    method: 'PUT',
    url: `${prefix}/Put`,
    data: {
      ...department
    }
  })
}


/**
 * SaveData2Tsv
 * @returns
 */
export const saveData2Tsv = () => {
  return http({
    method: 'GET',
    url: `${prefix}/SaveData2Tsv`,
  })
}
